#include "systemc.h"

SC_MODULE(count_stim) {
	sc_in_clk clock;
	sc_in<int> dout;
	sc_out<bool> load;
	sc_out<int> din;

	SC_CTOR(count_stim) {
		SC_THREAD(t_thread);
		sensitive << clock.pos();
		SC_CTHREAD(t_cthread, clock.pos());
		SC_METHOD(t_method);
		sensitive << clock.pos();
	}
	void t_method() {
		cout <<__func__ << ": " << sc_time_stamp() << endl;
	}
	void t_cthread(){
		cout <<__func__ << ": " << sc_time_stamp() << endl;
	}

	void t_thread() {
		while(true) {
			cout <<__func__ << ": " << sc_time_stamp() << endl;
			load = true;
			din = 0;
			wait();
			load = false;
		}
	}
};

int sc_main(int argc, char * argv[])
{
	sc_signal<int> dout;
	sc_signal<bool> load;
	sc_signal<int> din;
	sc_signal<bool> clock;

	count_stim ct("count_stim");
	ct.clock(clock);
	ct.dout(dout);
	ct.load(load);
	ct.din(din);

	// initlaize 
	// sc_start(SC_ZERO_TIME);
	for(int i=0; i<5; i++) {
		clock = 0;
		sc_start(1, SC_NS);
		clock = 1;
		sc_start(1, SC_NS);
	}
	return 0;
}
